package me.zhengjie.modules.finace_taxation.rest;

import com.alipay.api.internal.util.StringUtils;
import me.zhengjie.annotation.Log;
import me.zhengjie.modules.finace_taxation.domain.FtMeetings;
import me.zhengjie.modules.finace_taxation.service.FtMeetingsService;
import me.zhengjie.modules.finace_taxation.service.dto.FtMeetingsDto;
import me.zhengjie.modules.finace_taxation.service.dto.FtMeetingsQueryParam;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
* @author 杨荣森
* @date 2021-06-23
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "meetings管理")
@RequestMapping("/api/ft/ftMeetings")
public class FtMeetingsController {

    private final FtMeetingsService ftMeetingsService;

    @GetMapping
    @Log("查询会议")
    @ApiOperation("查询会议")
//    @PreAuthorize("@el.check('ftMeetings:list')")
    public ResponseEntity query(@RequestParam Map<String,Object> map, Pageable pageable){
        return new ResponseEntity<>(ftMeetingsService.queryAll(map, pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增会议")
    @ApiOperation("新增会议")
//    @PreAuthorize("@el.check('ftMeetings:add')")
    public ResponseEntity create(@Validated @RequestBody FtMeetingsDto resources){
        resources.setId("");
        return new ResponseEntity<>(ftMeetingsService.insert(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改会议")
    @ApiOperation("修改会议")
//    @PreAuthorize("@el.check('ftMeetings:edit')")
    public ResponseEntity update(@Validated @RequestBody FtMeetingsDto resources){
        ftMeetingsService.updateById(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除会议")
    @ApiOperation("删除会议")
//    @PreAuthorize("@el.check('ftMeetings:del')")
    public ResponseEntity delete(@RequestBody Set<String> ids) {
        ftMeetingsService.removeByIds(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    @GetMapping("/getByIndustryId")
    @Log("根据行业动态查询会议日程")
    @ApiOperation("根据行业动态查询会议日程")
//    @PreAuthorize("@el.check('ftMeetings:del')")
    public ResponseEntity getByIndustryId(@RequestParam(name="industryId",required=true)  String industryId) {
        List<FtMeetings> meetingsList = ftMeetingsService.getByIndustryId(industryId);
        return new ResponseEntity<>(meetingsList,HttpStatus.OK);
    }

    @Log("导出会议列表")
    @ApiOperation("导出会议列表")
    @GetMapping(value = "/download")
    public void download(HttpServletResponse response, FtMeetingsQueryParam query) throws IOException {
        ftMeetingsService.download(ftMeetingsService.queryAll(query), response);
    }

}
